package oj_leetcode;

import java.util.*;

public class Permutations {
    public List<List<Integer>> permute(int[] nums) {
        LinkedList<Integer> numlist = new LinkedList<>();
        for (int i = 0; i < nums.length; i++) {
            numlist.add(nums[i]);
        }
        return permute(numlist);
    }

    public List<List<Integer>> permute(LinkedList<Integer> nums) {
        List<List<Integer>> res = new LinkedList<>();
        if (nums.size() == 0) {
            res.add(new LinkedList<>());
            return res;
        }
        for (Integer num : nums) {
            LinkedList<Integer> numsTmp = new LinkedList<>(nums);
            numsTmp.remove(num);
            List<List<Integer>> tmp = permute(numsTmp);
            for (List<Integer> list : tmp) {
                list.add(0, num);
            }
            res.addAll(tmp);
        }
        return res;
    }

    public static void main(String[] args) {
        System.out.println(new Permutations().permute(new int[]{1, 2, 3}));
    }

}
